package cn.genmer.record.controller;


import cn.genmer.record.common.CommonResult;
import cn.genmer.record.dto.form.CoderForm;
import cn.genmer.record.model.Coder;
import cn.genmer.record.service.ICoderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import util.GeneratID;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyq
 * @since 2021-10-16
 */
@Api(tags = "用户控制器")
@Controller
@RequestMapping("/coder")
public class CoderController {

    @Autowired
    private ICoderService coderService;

    @ApiOperation("新增用户")
    @PostMapping("add")
    public CommonResult add(@RequestBody CoderForm coderForm){
        Coder coder = new Coder();
        BeanUtils.copyProperties(coderForm, coder);

        coder.setId(GeneratID.getGeneratID().toString());
        coder.setCreateTime(LocalDate.now());

        coderService.save(coder);

        return CommonResult.success("新增用户成功！");
    }
}